#if 0
	shc Version 4.0.3, Generic Shell Script Compiler
	GNU GPL Version 3 Md Jahidul Hamid <jahidulhamid@yahoo.com>

	shc -r -v -f clean_assetstype.sh 
#endif

static  char data [] = 
#define      shll_z	10
#define      shll	((&data[1]))
	"\004\355\332\014\365\217\251\211\157\250\355"
#define      text_z	2025
#define      text	((&data[101]))
	"\222\020\131\203\313\176\077\065\224\037\134\365\273\162\255\273"
	"\331\242\263\317\242\351\230\242\055\040\367\061\365\045\056\210"
	"\065\210\013\000\006\113\065\232\152\222\220\045\004\075\341\336"
	"\340\225\255\202\176\106\044\253\147\034\335\134\101\013\345\166"
	"\223\361\167\232\074\255\065\246\077\305\314\104\002\256\042\343"
	"\103\320\145\301\027\212\155\176\246\112\147\226\117\235\105\074"
	"\255\346\203\354\374\244\170\176\031\375\264\154\211\072\217\241"
	"\041\002\265\006\003\052\265\206\335\104\274\177\133\142\326\160"
	"\125\265\306\316\162\261\362\373\346\040\261\243\141\100\357\012"
	"\160\172\042\146\033\075\021\056\012\120\021\153\254\075\336\104"
	"\003\055\317\222\021\067\074\035\340\314\110\267\114\312\336\334"
	"\050\157\254\337\045\051\120\232\117\316\217\225\205\000\254\333"
	"\145\133\271\023\034\211\124\203\155\250\354\251\160\222\031\261"
	"\033\205\066\351\153\240\007\062\070\077\355\303\023\275\106\370"
	"\371\024\262\014\012\155\144\057\131\270\366\304\230\345\210\307"
	"\163\256\076\221\021\016\360\115\253\153\132\101\322\355\206\135"
	"\370\023\234\072\316\346\126\117\160\200\144\067\256\357\252\004"
	"\265\331\357\170\312\346\002\171\357\316\223\151\351\017\346\204"
	"\350\300\224\156\042\040\343\331\063\024\355\300\316\325\302\266"
	"\210\026\154\126\226\307\376\276\300\004\154\220\236\121\264\341"
	"\131\030\010\206\060\224\220\160\027\217\101\306\002\254\246\256"
	"\101\125\132\270\213\161\150\174\015\177\205\175\305\224\254\375"
	"\351\120\021\104\223\124\052\324\067\130\326\322\176\254\036\174"
	"\373\101\342\055\350\335\245\204\275\177\067\211\272\146\377\254"
	"\071\144\276\373\327\262\134\265\256\134\174\163\317\356\367\060"
	"\353\012\233\261\275\144\340\100\326\172\323\115\113\112\045\000"
	"\161\377\336\136\206\110\375\022\370\346\062\277\174\122\115\155"
	"\240\253\073\076\331\143\164\201\045\151\002\265\145\311\206\162"
	"\346\070\300\207\361\243\103\376\251\022\307\205\212\330\314\234"
	"\336\037\030\231\016\006\244\234\050\006\074\327\073\366\125\376"
	"\076\017\267\014\031\143\005\240\266\300\056\045\045\046\332\243"
	"\045\264\303\352\220\052\146\007\077\356\372\330\004\145\375\256"
	"\277\115\222\212\066\377\072\127\347\001\237\066\112\067\174\104"
	"\055\321\023\103\173\367\327\017\164\170\032\260\357\366\240\164"
	"\327\337\020\074\220\332\335\036\133\164\264\023\125\320\366\372"
	"\201\106\306\244\202\322\117\111\364\361\235\235\372\127\333\057"
	"\126\021\117\135\353\164\351\034\200\110\103\224\014\225\375\336"
	"\004\216\011\037\066\222\010\200\035\135\056\271\112\111\334\261"
	"\162\135\001\315\142\101\276\316\107\222\223\237\105\371\012\321"
	"\110\343\036\360\332\174\034\264\154\233\270\204\057\222\046\330"
	"\303\057\245\347\066\072\356\173\161\065\175\375\340\335\346\365"
	"\300\303\123\201\336\042\163\126\043\122\247\017\173\313\324\352"
	"\214\271\022\250\255\163\045\061\144\207\017\147\025\370\155\044"
	"\275\015\133\265\320\313\020\034\112\171\254\170\106\061\343\232"
	"\156\124\212\075\003\010\312\115\151\263\342\112\171\332\244\322"
	"\255\157\214\322\322\301\323\255\214\206\035\163\355\031\246\113"
	"\321\177\162\370\376\271\302\066\255\365\151\101\016\201\175\345"
	"\136\060\204\256\072\233\146\362\112\013\162\255\264\332\141\043"
	"\074\372\355\246\040\204\216\302\041\202\361\244\150\313\327\051"
	"\115\100\052\055\051\362\212\056\062\061\330\076\145\351\102\140"
	"\331\162\024\221\347\221\022\073\207\216\260\070\355\350\164\012"
	"\152\053\105\077\226\272\037\200\002\151\061\044\334\031\116\032"
	"\166\022\347\120\033\377\350\354\167\113\004\144\140\254\353\123"
	"\377\333\306\264\336\100\357\371\237\372\100\122\351\324\200\033"
	"\353\134\103\250\364\261\366\120\220\175\252\122\231\225\010\062"
	"\255\341\335\225\347\203\311\061\300\137\223\005\013\341\170\220"
	"\137\166\325\114\357\160\271\115\160\205\224\011\315\031\033\333"
	"\071\361\017\252\034\341\247\363\006\321\243\035\232\363\267\122"
	"\134\155\204\253\174\237\273\376\333\210\371\034\117\130\261\124"
	"\124\350\123\026\036\223\122\065\105\072\077\133\247\063\104\166"
	"\206\205\035\200\013\321\246\113\067\217\311\050\125\116\272\354"
	"\036\152\205\270\172\345\115\247\307\323\361\160\241\336\054\234"
	"\105\043\244\317\044\111\333\322\216\110\315\207\303\077\000\345"
	"\365\211\074\100\053\055\172\105\066\277\272\021\126\123\164\163"
	"\311\170\116\045\157\226\217\170\341\046\305\274\160\302\303\067"
	"\006\342\337\266\333\353\134\111\326\136\054\366\311\360\311\363"
	"\306\123\322\124\330\130\225\352\303\054\272\000\332\144\065\320"
	"\300\321\131\360\315\326\334\175\157\114\364\217\312\234\065\323"
	"\371\347\327\351\112\011\065\344\120\101\325\370\044\201\022\000"
	"\113\030\222\122\014\175\003\353\227\132\213\267\355\136\340\202"
	"\174\355\142\031\131\154\331\267\003\051\374\246\055\226\257\043"
	"\062\064\035\274\316\156\346\312\126\161\300\020\047\160\251\207"
	"\340\245\124\024\334\323\172\207\055\217\114\142\152\237\137\300"
	"\207\236\342\270\141\113\210\070\350\214\231\306\307\202\050\376"
	"\047\342\031\131\266\346\107\151\075\102\060\261\203\056\134\340"
	"\226\265\116\247\040\203\111\164\062\122\013\036\211\317\354\243"
	"\177\356\065\016\142\066\366\336\002\316\214\335\360\313\356\070"
	"\333\224\145\234\036\373\140\211\324\307\353\142\156\051\254\046"
	"\362\122\220\164\233\363\340\045\375\164\174\211\021\334\036\372"
	"\341\140\245\042\242\023\131\307\306\374\076\263\164\216\305\067"
	"\016\132\052\102\374\035\254\030\350\011\304\236\233\326\351\040"
	"\066\222\002\162\110\342\170\231\001\352\177\222\257\202\256\140"
	"\145\367\125\277\134\344\245\302\270\053\307\352\013\002\270\055"
	"\320\204\054\060\042\050\231\307\205\326\127\352\267\055\225\300"
	"\077\127\010\255\057\265\070\073\051\104\215\142\113\200\206\033"
	"\064\236\036\030\270\015\152\351\303\150\164\007\214\166\342\102"
	"\367\170\001\365\234\024\214\125\003\012\067\272\235\155\070\067"
	"\056\060\254\212\173\230\145\313\021\267\136\266\334\234\327\340"
	"\004\046\377\324\104\154\170\173\172\032\144\234\337\170\116\271"
	"\170\025\045\032\022\020\252\030\160\016\336\017\247\353\240\211"
	"\317\012\350\076\335\235\213\030\256\217\245\264\211\316\064\237"
	"\077\354\246\267\024\042\342\351\126\211\073\175\157\164\214\273"
	"\361\263\063\352\310\330\275\166\022\070\060\240\363\073\160\050"
	"\251\123\315\102\026\156\161\331\221\350\017\357\254\336\217\102"
	"\273\173\072\212\002\342\331\304\253\162\043\236\360\334\371\154"
	"\017\374\016\272\004\332\111\123\171\206\352\322\200\032\043\103"
	"\247\043\047\245\216\062\334\355\035\045\033\230\200\303\141\312"
	"\177\142\335\255\300\054\213\167\244\322\346\022\103\302\027\205"
	"\343\306\057\262\323\171\240\124\023\057\360\035\254\121\330\141"
	"\273\100\265\331\010\227\265\332\145\032\233\271\373\002\120\026"
	"\203\242\123\325\311\231\275\327\271\000\161\335\010\357\175\070"
	"\041\105\152\344\335\302\245\065\213\135\053\366\142\317\262\243"
	"\257\277\231\065\341\046\040\040\347\234\165\020\132\043\275\072"
	"\347\315\032\323\150\001\375\122\343\045\217\375\245\245\033\352"
	"\005\264\325\217\356\325\204\201\343\044\307\260\216\156\214\256"
	"\150\071\331\161\334\270\330\151\265\277\057\320\157\171\372\322"
	"\377\325\232\106\252\354\006\133\035\006\173\040\234\003\223\205"
	"\375\000\323\077\315\165\353\056\161\175\131\024\377\023\155\054"
	"\170\135\352\267\310\261\112\211\325\110\065\010\043\130\207\254"
	"\221\355\000\346\056\362\004\061\127\255\133\346\132\006\351\066"
	"\111\251\065\134\155\146\250\142\175\205\371\072\214\063\075\206"
	"\315\206\113\250\077\301\261\216\222\172\315\250\104\022\141\260"
	"\316\260\173\050\033\252\251\143\266\326\013\366\125\363\367\012"
	"\336\041\307\273\232\366\071\315\006\327\364\076\353\222\123\310"
	"\002\231\245\344\220\152\361\034\245\052\150\315\340\066\272\275"
	"\222\227\304\031\356\167\305\362\050\003\144\020\111\221\052\002"
	"\132\336\040\212\214\063\047\356\223\206\231\067\102\210\317\036"
	"\023\303\073\064\361\345\233\256\005\076\115\140\236\242\033\226"
	"\263\254\260\160\315\354\024\105\322\155\217\107\210\215\016\067"
	"\137\170\267\247\117\265\250\041\323\223\325\023\223\321\207\253"
	"\153\134\231\270\300\214\334\322\062\267\061\116\376\206\014\022"
	"\067\375\042\010\000\104\320\317\024\137\060\203\167\166\115\252"
	"\207\074\233\113\245\027\111\352\171\135\243\204\121\164\071\111"
	"\043\114\150\322\367\246\074\153\174\322\136\302\135\157\366\371"
	"\107\207\241\220\343\152\051\063\126\312\133\160\072\100\311\203"
	"\230\223\312\363\321\300\261\116\367\345\001\075\372\037\352\277"
	"\332\162\062\350\105\342\251\062\166\010\304\354\302\121\314\102"
	"\207\245\332\316\315\213\227\027\025\242\136\354\344\060\235\312"
	"\167\340\352\264\246\001\344\352\302\044\013\113\121\242\217\254"
	"\325\124\364\375\034\321\073\050\133\146\175\210\303\367\232\173"
	"\056\335\006\236\362\316\177\104\020\162\001\157\070\333\231\256"
	"\315\251\022\215\053\327\145\173\361\256\025\332\325\041\142\123"
	"\127\130\077\333\350\125\300\136\351\262\326\203\356\204\270\225"
	"\304\175\141\010\200\017\053\143\123\374\311\024\023\123\202\222"
	"\372\315\156\342\043\057\101\014\341\030\217\317\234\110\144\140"
	"\305\306\151\106\326\225\252\051\222\163\076\245\307\300\070\301"
	"\215\246\244\261\325\345\275\266\376\115\206\232\225\353\373\133"
	"\262\144\241\210\372\113\262\214\277\360\062\206\261\152\110\077"
	"\021\355\360\347\322\255\235\321\373\044\153\220\020\146\354\302"
	"\313\216\112\306\332\374\122\231\355\204\040\236\357\150\335\001"
	"\125\316\350\050\173\206\371\167\252\145\010\272\314\364\174\230"
	"\203\307\136\135\304\261\366\262\066\026\120\045\177\056\046\325"
	"\374\017\375\170\225\367\357\077\135\370\372\051\354\167\301\157"
	"\077\040\315\004\321\303\266\007\332\006\054\131\065\123\056\061"
	"\142\054\252\370\044\232\070\201\222\062\253\177\252\155\356\351"
	"\215\273\355\136\177\243\145\131\252\222\263\340\346\342\022\111"
	"\016\274\101\063\126\171\265\350\254\140\147\126\315\126\077\132"
	"\022\055\271\222\321\036\353\174\260\237\134\226\201\156\340\220"
	"\053\041\303\201\232\170\152\106\331\321\234\246\050\334\001\073"
	"\012\272\315\333\331\271\130\211\130\264\040\332\043\000\152\116"
	"\042\056\317\275\247\072\003\201\014\240\050\064\175\051\157\207"
	"\344\075\143\275\366\273\107\117\157\150\052\223\151\224\341\213"
	"\303\261\110\153\353\114\354\367\355\024\054\152\076\234\361\042"
	"\331\125\340\320\020\047\040\200\220\112\023\371\337\364\205\243"
	"\246\316\016\222\032\372\212\007\017\266\162\115\123\143\160\054"
	"\270\120\375\311\170\035\111\010\150\134\001\107\121\207\352\370"
	"\125\371\212\160\364\024\167\003\313\351\120\036\115\300\112\006"
	"\021\110\317\211\146\031\221\316\165\223\026\307\032\001\277\160"
	"\372\112\340\356\136\130\362\051\102\102\107\217\003\222\226\025"
	"\333\146\236\101\177\060\020\365\303\047\274\336\051\174\117\043"
	"\307\057\022\045\210\004\117\312\107\227\132\113\052\360\140\006"
	"\127\376\110\326\056\131\314\362\200\211\321\251\005\040\315\314"
	"\120\340\362\330\344\102\242\054\332\374\167\004\355\330\012\104"
	"\327\123\033\006\254\347\370"
#define      date_z	1
#define      date	((&data[2626]))
	"\302"
#define      tst2_z	19
#define      tst2	((&data[2629]))
	"\243\103\201\156\133\155\230\313\224\153\373\257\101\025\077\155"
	"\376\347\012\163\060\072\203\065\022"
#define      lsto_z	1
#define      lsto	((&data[2652]))
	"\125"
#define      chk1_z	22
#define      chk1	((&data[2654]))
	"\014\265\346\046\105\121\346\231\150\075\245\073\222\347\157\076"
	"\323\327\313\214\117\002\035\126\237\345\141"
#define      chk2_z	19
#define      chk2	((&data[2683]))
	"\377\302\140\270\157\336\311\135\224\051\354\175\055\025\301\315"
	"\250\244\216\106\304\277\347\273\215"
#define      xecc_z	15
#define      xecc	((&data[2707]))
	"\316\157\154\343\173\216\256\136\036\302\351\374\060\135\340\006"
	"\212\007"
#define      msg1_z	65
#define      msg1	((&data[2734]))
	"\107\274\363\277\161\210\021\043\225\150\303\212\224\060\200\160"
	"\351\231\341\236\047\032\140\231\203\242\225\255\116\317\143\045"
	"\062\016\315\063\012\042\157\121\100\057\042\323\071\373\064\073"
	"\125\077\277\321\176\363\027\215\117\330\120\306\004\324\063\314"
	"\022\351\363\073\331\217\047\225\366\301\262\076\172\312\247\066"
	"\177\247\371\340\216"
#define      rlax_z	1
#define      rlax	((&data[2808]))
	"\345"
#define      inlo_z	3
#define      inlo	((&data[2809]))
	"\007\012\062"
#define      msg2_z	19
#define      msg2	((&data[2816]))
	"\123\143\016\020\045\106\012\201\230\165\206\137\154\101\276\154"
	"\276\226\272\266\113\004\344\126\316\201"
#define      pswd_z	256
#define      pswd	((&data[2894]))
	"\164\111\150\356\023\017\045\222\267\037\162\105\323\340\054\015"
	"\261\341\267\211\250\012\355\266\032\104\205\234\043\145\101\227"
	"\256\252\206\301\272\254\124\161\313\307\267\237\250\343\255\131"
	"\305\144\343\155\157\320\044\212\245\003\073\351\143\324\033\075"
	"\142\054\230\327\064\070\056\264\223\173\366\025\373\325\362\212"
	"\156\112\173\060\214\123\356\062\126\052\033\272\376\066\367\141"
	"\143\220\070\227\310\147\114\134\343\102\161\336\030\144\150\206"
	"\256\344\266\073\067\245\155\215\320\211\107\316\277\077\060\043"
	"\320\151\272\230\320\007\365\263\111\146\221\142\312\372\351\170"
	"\336\237\264\026\105\041\243\025\252\353\344\152\053\024\215\373"
	"\175\110\224\115\117\212\001\231\361\222\373\273\215\344\064\153"
	"\204\350\201\312\012\045\340\264\021\304\036\075\331\253\071\126"
	"\364\316\244\103\130\245\335\111\070\330\005\305\275\072\060\102"
	"\043\262\015\055\330\355\341\351\261\000\046\212\253\137\341\240"
	"\056\206\343\206\053\300\317\143\231\324\051\127\017\131\231\062"
	"\014\246\137\344\224\101\316\105\101\365\320\355\125\262\215\203"
	"\070\161\011\144\062\331\307\313\256\361\043\275\113\274\357\127"
	"\143\117\074\367\220\012\075\321\000\016\277\125\300\114\330\370"
	"\276\342\134\360\273\044\274\151\025\337\047\140\234\026\270\000"
	"\146\364\370\366\377\065\310\377\024\251\047\067\017\151\317\275"
	"\023\126\177\316\003\324\077\316\233\366\156\103\332\033\235\240"
	"\177\200\016\357\121\062\172\145\334\241\235\354\012\155\251\036"
	"\304"
#define      tst1_z	22
#define      tst1	((&data[3196]))
	"\375\053\226\231\042\275\053\106\026\240\271\063\246\060\243\314"
	"\267\340\322\113\145\375\000\076\155\045\167\004\335\375\037"
#define      opts_z	1
#define      opts	((&data[3222]))
	"\031"/* End of data[] */;
#define      hide_z	4096
#define SETUID 0	/* Define as 1 to call setuid(0) at start of script */
#define DEBUGEXEC	0	/* Define as 1 to debug execvp calls */
#define TRACEABLE	1	/* Define as 1 to enable ptrace the executable */
#define HARDENING	0	/* Define as 1 to disable ptrace/dump the executable */
#define BUSYBOXON	0	/* Define as 1 to enable work with busybox */

#if HARDENING
static const char * shc_x[] = {
"/*",
" * Copyright 2019 - Intika <intika@librefox.org>",
" * Replace ******** with secret read from fd 21",
" * Also change arguments location of sub commands (sh script commands)",
" * gcc -Wall -fpic -shared -o shc_secret.so shc_secret.c -ldl",
" */",
"",
"#define _GNU_SOURCE /* needed to get RTLD_NEXT defined in dlfcn.h */",
"#define PLACEHOLDER \"********\"",
"#include <dlfcn.h>",
"#include <stdlib.h>",
"#include <string.h>",
"#include <unistd.h>",
"#include <stdio.h>",
"#include <signal.h>",
"",
"static char secret[128000]; //max size",
"typedef int (*pfi)(int, char **, char **);",
"static pfi real_main;",
"",
"// copy argv to new location",
"char **copyargs(int argc, char** argv){",
"    char **newargv = malloc((argc+1)*sizeof(*argv));",
"    char *from,*to;",
"    int i,len;",
"",
"    for(i = 0; i<argc; i++){",
"        from = argv[i];",
"        len = strlen(from)+1;",
"        to = malloc(len);",
"        memcpy(to,from,len);",
"        // zap old argv space",
"        memset(from,'\\0',len);",
"        newargv[i] = to;",
"        argv[i] = 0;",
"    }",
"    newargv[argc] = 0;",
"    return newargv;",
"}",
"",
"static int mymain(int argc, char** argv, char** env) {",
"    //fprintf(stderr, \"Inject main argc = %d\\n\", argc);",
"    return real_main(argc, copyargs(argc,argv), env);",
"}",
"",
"int __libc_start_main(int (*main) (int, char**, char**),",
"                      int argc,",
"                      char **argv,",
"                      void (*init) (void),",
"                      void (*fini)(void),",
"                      void (*rtld_fini)(void),",
"                      void (*stack_end)){",
"    static int (*real___libc_start_main)() = NULL;",
"    int n;",
"",
"    if (!real___libc_start_main) {",
"        real___libc_start_main = dlsym(RTLD_NEXT, \"__libc_start_main\");",
"        if (!real___libc_start_main) abort();",
"    }",
"",
"    n = read(21, secret, sizeof(secret));",
"    if (n > 0) {",
"      int i;",
"",
"    if (secret[n - 1] == '\\n') secret[--n] = '\\0';",
"    for (i = 1; i < argc; i++)",
"        if (strcmp(argv[i], PLACEHOLDER) == 0)",
"          argv[i] = secret;",
"    }",
"",
"    real_main = main;",
"",
"    return real___libc_start_main(mymain, argc, argv, init, fini, rtld_fini, stack_end);",
"}",
"",
0};
#endif /* HARDENING */

/* rtc.c */

#include <sys/stat.h>
#include <sys/types.h>

#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <unistd.h>

/* 'Alleged RC4' */

static unsigned char stte[256], indx, jndx, kndx;

/*
 * Reset arc4 stte. 
 */
void stte_0(void)
{
	indx = jndx = kndx = 0;
	do {
		stte[indx] = indx;
	} while (++indx);
}

/*
 * Set key. Can be used more than once. 
 */
void key(void * str, int len)
{
	unsigned char tmp, * ptr = (unsigned char *)str;
	while (len > 0) {
		do {
			tmp = stte[indx];
			kndx += tmp;
			kndx += ptr[(int)indx % len];
			stte[indx] = stte[kndx];
			stte[kndx] = tmp;
		} while (++indx);
		ptr += 256;
		len -= 256;
	}
}

/*
 * Crypt data. 
 */
void arc4(void * str, int len)
{
	unsigned char tmp, * ptr = (unsigned char *)str;
	while (len > 0) {
		indx++;
		tmp = stte[indx];
		jndx += tmp;
		stte[indx] = stte[jndx];
		stte[jndx] = tmp;
		tmp += stte[indx];
		*ptr ^= stte[tmp];
		ptr++;
		len--;
	}
}

/* End of ARC4 */

#if HARDENING

#include <sys/ptrace.h>
#include <sys/wait.h>
#include <signal.h>
#include <sys/prctl.h>
#define PR_SET_PTRACER 0x59616d61

/* Seccomp Sandboxing Init */
#include <stdlib.h>
#include <stdio.h>
#include <stddef.h>
#include <string.h>
#include <unistd.h>
#include <errno.h>

#include <sys/types.h>
#include <sys/prctl.h>
#include <sys/syscall.h>
#include <sys/socket.h>

#include <linux/filter.h>
#include <linux/seccomp.h>
#include <linux/audit.h>

#define ArchField offsetof(struct seccomp_data, arch)

#define Allow(syscall) \
    BPF_JUMP(BPF_JMP+BPF_JEQ+BPF_K, SYS_##syscall, 0, 1), \
    BPF_STMT(BPF_RET+BPF_K, SECCOMP_RET_ALLOW)

struct sock_filter filter[] = {
    /* validate arch */
    BPF_STMT(BPF_LD+BPF_W+BPF_ABS, ArchField),
    BPF_JUMP( BPF_JMP+BPF_JEQ+BPF_K, AUDIT_ARCH_X86_64, 1, 0),
    BPF_STMT(BPF_RET+BPF_K, SECCOMP_RET_KILL),

    /* load syscall */
    BPF_STMT(BPF_LD+BPF_W+BPF_ABS, offsetof(struct seccomp_data, nr)),

    /* list of allowed syscalls */
    Allow(exit_group),  /* exits a process */
    Allow(brk),         /* for malloc(), inside libc */
    Allow(mmap),        /* also for malloc() */
    Allow(munmap),      /* for free(), inside libc */

    /* and if we don't match above, die */
    BPF_STMT(BPF_RET+BPF_K, SECCOMP_RET_KILL),
};
struct sock_fprog filterprog = {
    .len = sizeof(filter)/sizeof(filter[0]),
    .filter = filter
};

/* Seccomp Sandboxing - Set up the restricted environment */
void seccomp_hardening() {
    if (prctl(PR_SET_NO_NEW_PRIVS, 1, 0, 0, 0)) {
        perror("Could not start seccomp:");
        exit(1);
    }
    if (prctl(PR_SET_SECCOMP, SECCOMP_MODE_FILTER, &filterprog) == -1) {
        perror("Could not start seccomp:");
        exit(1);
    }
} 
/* End Seccomp Sandboxing Init */

void shc_x_file() {
    FILE *fp;
    int line = 0;

    if ((fp = fopen("/tmp/shc_x.c", "w")) == NULL ) {exit(1); exit(1);}
    for (line = 0; shc_x[line]; line++)	fprintf(fp, "%s\n", shc_x[line]);
    fflush(fp);fclose(fp);
}

int make() {
	char * cc, * cflags, * ldflags;
    char cmd[4096];

	cc = getenv("CC");
	if (!cc) cc = "cc";

	sprintf(cmd, "%s %s -o %s %s", cc, "-Wall -fpic -shared", "/tmp/shc_x.so", "/tmp/shc_x.c -ldl");
	if (system(cmd)) {remove("/tmp/shc_x.c"); return -1;}
	remove("/tmp/shc_x.c"); return 0;
}

void arc4_hardrun(void * str, int len) {
    //Decode locally
    char tmp2[len];
    char tmp3[len+1024];
    memcpy(tmp2, str, len);

	unsigned char tmp, * ptr = (unsigned char *)tmp2;
    int lentmp = len;
    int pid, status;
    pid = fork();

    shc_x_file();
    if (make()) {exit(1);}

    setenv("LD_PRELOAD","/tmp/shc_x.so",1);

    if(pid==0) {

        //Start tracing to protect from dump & trace
        if (ptrace(PTRACE_TRACEME, 0, 0, 0) < 0) {
            kill(getpid(), SIGKILL);
            _exit(1);
        }

        //Decode Bash
        while (len > 0) {
            indx++;
            tmp = stte[indx];
            jndx += tmp;
            stte[indx] = stte[jndx];
            stte[jndx] = tmp;
            tmp += stte[indx];
            *ptr ^= stte[tmp];
            ptr++;
            len--;
        }

        //Do the magic
        sprintf(tmp3, "%s %s", "'********' 21<<<", tmp2);

        //Exec bash script //fork execl with 'sh -c'
        system(tmp2);

        //Empty script variable
        memcpy(tmp2, str, lentmp);

        //Clean temp
        remove("/tmp/shc_x.so");

        //Sinal to detach ptrace
        ptrace(PTRACE_DETACH, 0, 0, 0);
        exit(0);
    }
    else {wait(&status);}

    /* Seccomp Sandboxing - Start */
    seccomp_hardening();

    exit(0);
}
#endif /* HARDENING */

/*
 * Key with file invariants. 
 */
int key_with_file(char * file)
{
	struct stat statf[1];
	struct stat control[1];

	if (stat(file, statf) < 0)
		return -1;

	/* Turn on stable fields */
	memset(control, 0, sizeof(control));
	control->st_ino = statf->st_ino;
	control->st_dev = statf->st_dev;
	control->st_rdev = statf->st_rdev;
	control->st_uid = statf->st_uid;
	control->st_gid = statf->st_gid;
	control->st_size = statf->st_size;
	control->st_mtime = statf->st_mtime;
	control->st_ctime = statf->st_ctime;
	key(control, sizeof(control));
	return 0;
}

#if DEBUGEXEC
void debugexec(char * sh11, int argc, char ** argv)
{
	int i;
	fprintf(stderr, "shll=%s\n", sh11 ? sh11 : "<null>");
	fprintf(stderr, "argc=%d\n", argc);
	if (!argv) {
		fprintf(stderr, "argv=<null>\n");
	} else { 
		for (i = 0; i <= argc ; i++)
			fprintf(stderr, "argv[%d]=%.60s\n", i, argv[i] ? argv[i] : "<null>");
	}
}
#endif /* DEBUGEXEC */

void rmarg(char ** argv, char * arg)
{
	for (; argv && *argv && *argv != arg; argv++);
	for (; argv && *argv; argv++)
		*argv = argv[1];
}

void chkenv_end(void);

int chkenv(int argc)
{
	char buff[512];
	unsigned long mask, m;
	int l, a, c;
	char * string;
	extern char ** environ;

	mask = (unsigned long)getpid();
	stte_0();
	 key(&chkenv, (void*)&chkenv_end - (void*)&chkenv);
	 key(&data, sizeof(data));
	 key(&mask, sizeof(mask));
	arc4(&mask, sizeof(mask));
	sprintf(buff, "x%lx", mask);
	string = getenv(buff);
#if DEBUGEXEC
	fprintf(stderr, "getenv(%s)=%s\n", buff, string ? string : "<null>");
#endif
	l = strlen(buff);
	if (!string) {
		/* 1st */
		sprintf(&buff[l], "=%lu %d", mask, argc);
		putenv(strdup(buff));
		return 0;
	}
	c = sscanf(string, "%lu %d%c", &m, &a, buff);
	if (c == 2 && m == mask) {
		/* 3rd */
		rmarg(environ, &string[-l - 1]);
		return 1 + (argc - a);
	}
	return -1;
}

void chkenv_end(void){}

#if HARDENING

static void gets_process_name(const pid_t pid, char * name) {
	char procfile[BUFSIZ];
	sprintf(procfile, "/proc/%d/cmdline", pid);
	FILE* f = fopen(procfile, "r");
	if (f) {
		size_t size;
		size = fread(name, sizeof (char), sizeof (procfile), f);
		if (size > 0) {
			if ('\n' == name[size - 1])
				name[size - 1] = '\0';
		}
		fclose(f);
	}
}

void hardening() {
    prctl(PR_SET_DUMPABLE, 0);
    prctl(PR_SET_PTRACER, -1);

    int pid = getppid();
    char name[256] = {0};
    gets_process_name(pid, name);

    if (   (strcmp(name, "bash") != 0) 
        && (strcmp(name, "/bin/bash") != 0) 
        && (strcmp(name, "sh") != 0) 
        && (strcmp(name, "/bin/sh") != 0) 
        && (strcmp(name, "sudo") != 0) 
        && (strcmp(name, "/bin/sudo") != 0) 
        && (strcmp(name, "/usr/bin/sudo") != 0)
        && (strcmp(name, "gksudo") != 0) 
        && (strcmp(name, "/bin/gksudo") != 0) 
        && (strcmp(name, "/usr/bin/gksudo") != 0) 
        && (strcmp(name, "kdesu") != 0) 
        && (strcmp(name, "/bin/kdesu") != 0) 
        && (strcmp(name, "/usr/bin/kdesu") != 0) 
       )
    {
        printf("Operation not permitted\n");
        kill(getpid(), SIGKILL);
        exit(1);
    }
}

#endif /* HARDENING */

#if !TRACEABLE

#define _LINUX_SOURCE_COMPAT
#include <sys/ptrace.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <fcntl.h>
#include <signal.h>
#include <stdio.h>
#include <unistd.h>

#if !defined(PT_ATTACHEXC) /* New replacement for PT_ATTACH */
   #if !defined(PTRACE_ATTACH) && defined(PT_ATTACH)
       #define PT_ATTACHEXC	PT_ATTACH
   #elif defined(PTRACE_ATTACH)
       #define PT_ATTACHEXC PTRACE_ATTACH
   #endif
#endif

void untraceable(char * argv0)
{
	char proc[80];
	int pid, mine;

	switch(pid = fork()) {
	case  0:
		pid = getppid();
		/* For problematic SunOS ptrace */
#if defined(__FreeBSD__)
		sprintf(proc, "/proc/%d/mem", (int)pid);
#else
		sprintf(proc, "/proc/%d/as",  (int)pid);
#endif
		close(0);
		mine = !open(proc, O_RDWR|O_EXCL);
		if (!mine && errno != EBUSY)
			mine = !ptrace(PT_ATTACHEXC, pid, 0, 0);
		if (mine) {
			kill(pid, SIGCONT);
		} else {
			perror(argv0);
			kill(pid, SIGKILL);
		}
		_exit(mine);
	case -1:
		break;
	default:
		if (pid == waitpid(pid, 0, 0))
			return;
	}
	perror(argv0);
	_exit(1);
}
#endif /* !TRACEABLE */

char * xsh(int argc, char ** argv)
{
	char * scrpt;
	int ret, i, j;
	char ** varg;
	char * me = argv[0];
	if (me == NULL) { me = getenv("_"); }
	if (me == 0) { fprintf(stderr, "E: neither argv[0] nor $_ works."); exit(1); }

	ret = chkenv(argc);
	stte_0();
	 key(pswd, pswd_z);
	arc4(msg1, msg1_z);
	arc4(date, date_z);
	if (date[0] && (atoll(date)<time(NULL)))
		return msg1;
	arc4(shll, shll_z);
	arc4(inlo, inlo_z);
	arc4(xecc, xecc_z);
	arc4(lsto, lsto_z);
	arc4(tst1, tst1_z);
	 key(tst1, tst1_z);
	arc4(chk1, chk1_z);
	if ((chk1_z != tst1_z) || memcmp(tst1, chk1, tst1_z))
		return tst1;
	arc4(msg2, msg2_z);
	if (ret < 0)
		return msg2;
	varg = (char **)calloc(argc + 10, sizeof(char *));
	if (!varg)
		return 0;
	if (ret) {
		arc4(rlax, rlax_z);
		if (!rlax[0] && key_with_file(shll))
			return shll;
		arc4(opts, opts_z);
#if HARDENING
	    arc4_hardrun(text, text_z);
	    exit(0);
       /* Seccomp Sandboxing - Start */
       seccomp_hardening();
#endif
		arc4(text, text_z);
		arc4(tst2, tst2_z);
		 key(tst2, tst2_z);
		arc4(chk2, chk2_z);
		if ((chk2_z != tst2_z) || memcmp(tst2, chk2, tst2_z))
			return tst2;
		/* Prepend hide_z spaces to script text to hide it. */
		scrpt = malloc(hide_z + text_z);
		if (!scrpt)
			return 0;
		memset(scrpt, (int) ' ', hide_z);
		memcpy(&scrpt[hide_z], text, text_z);
	} else {			/* Reexecute */
		if (*xecc) {
			scrpt = malloc(512);
			if (!scrpt)
				return 0;
			sprintf(scrpt, xecc, me);
		} else {
			scrpt = me;
		}
	}
	j = 0;
#if BUSYBOXON
	varg[j++] = "busybox";
	varg[j++] = "sh";
#else
	varg[j++] = argv[0];		/* My own name at execution */
#endif
	if (ret && *opts)
		varg[j++] = opts;	/* Options on 1st line of code */
	if (*inlo)
		varg[j++] = inlo;	/* Option introducing inline code */
	varg[j++] = scrpt;		/* The script itself */
	if (*lsto)
		varg[j++] = lsto;	/* Option meaning last option */
	i = (ret > 1) ? ret : 0;	/* Args numbering correction */
	while (i < argc)
		varg[j++] = argv[i++];	/* Main run-time arguments */
	varg[j] = 0;			/* NULL terminated array */
#if DEBUGEXEC
	debugexec(shll, j, varg);
#endif
	execvp(shll, varg);
	return shll;
}

int main(int argc, char ** argv)
{
#if SETUID
   setuid(0);
#endif
#if DEBUGEXEC
	debugexec("main", argc, argv);
#endif
#if HARDENING
	hardening();
#endif
#if !TRACEABLE
	untraceable(argv[0]);
#endif
	argv[1] = xsh(argc, argv);
	fprintf(stderr, "%s%s%s: %s\n", argv[0],
		errno ? ": " : "",
		errno ? strerror(errno) : "",
		argv[1] ? argv[1] : "<null>"
	);
	return 1;
}
